package com.example.httprequest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;

import org.jetbrains.annotations.NotNull;
import org.json.JSONException;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // 异步get
        HttpUtil.getAsync("http://121.43.236.195:8081/user/1", new ResponseCallBack() {
            @Override
            public void onSuccess(String res) {
                Log.i("abcdefg", "1111------------------------");
                Looper.prepare();
                Toast.makeText(getApplicationContext(), res, Toast.LENGTH_SHORT).show();
                Looper.loop();
            }

            @Override
            public void onException(Exception e) {
                Log.i("abcdefg", "2222------------------------");
                Looper.prepare();
                Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                Looper.loop();
            }
        });

        Log.i("abcdefg", "dddd------------------------");



    }


}